From f2af2d95f03ae3e24e0403f1e00a9e68decd967d Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 13 Sep 2010 17:24:44 +0100 Subject: [PATCH] vmx: Caching the VMCS field EXCEPTION_BITMAP and cleanup some unused function. Signed-off-by: Qing He Signed-off-by: Eddie Dong --- xen/arch/x86/hvm/vmx/vmcs.c | 6 +++--- xen/arch/x86/hvm/vmx/vmx.c | 29 ++++++++++++++++++----------- xen/include/asm-x86/hvm/vmx/vmcs.h | 1 + xen/include/asm-x86/hvm/vmx/vmx.h | 12 ++---------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index 7b93aeed2b..1498db06ec 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -839,10 +839,10 @@ static int construct_vmcs(struct vcpu *v) __vmwrite(VMCS_LINK_POINTER_HIGH, ~0UL); #endif - __vmwrite(EXCEPTION_BITMAP, - HVM_TRAP_MASK + v->arch.hvm_vmx.exception_bitmap = HVM_TRAP_MASK | (paging_mode_hap(d) ? 0 : (1U << TRAP_page_fault)) - | (1U << TRAP_no_device)); + | (1U << TRAP_no_device); + vmx_update_exception_bitmap(v); v->arch.hvm_vcpu.guest_cr[0] = X86_CR0_PE | X86_CR0_ET; hvm_update_guest_cr(v, 0); diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index ed2bf325f4..e89ed302e6 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -385,6 +385,11 @@ long_mode_do_msr_write(unsigned int msr, uint64_t msr_content) #endif /* __i386__ */ +void vmx_update_exception_bitmap(struct vcpu *v) +{ + __vmwrite(EXCEPTION_BITMAP, v->arch.hvm_vmx.exception_bitmap); +} + static int vmx_guest_x86_mode(struct vcpu *v) { unsigned int cs_ar_bytes; @@ -623,7 +628,8 @@ static int vmx_load_vmcs_ctxt(struct vcpu *v, struct hvm_hw_cpu *ctxt) static void vmx_fpu_enter(struct vcpu *v) { setup_fpu(v); - __vm_clear_bit(EXCEPTION_BITMAP, TRAP_no_device); + v->arch.hvm_vmx.exception_bitmap &= ~(1u << TRAP_no_device); + vmx_update_exception_bitmap(v); v->arch.hvm_vmx.host_cr0 &= ~X86_CR0_TS; __vmwrite(HOST_CR0, v->arch.hvm_vmx.host_cr0); } @@ -649,7 +655,8 @@ static void vmx_fpu_leave(struct vcpu *v) { v->arch.hvm_vcpu.hw_cr[0] |= X86_CR0_TS; __vmwrite(GUEST_CR0, v->arch.hvm_vcpu.hw_cr[0]); - __vm_set_bit(EXCEPTION_BITMAP, TRAP_no_device); + v->arch.hvm_vmx.exception_bitmap |= (1u << TRAP_no_device); + vmx_update_exception_bitmap(v); } } @@ -1049,7 +1056,7 @@ static void vmx_update_host_cr3(struct vcpu *v) void vmx_update_debug_state(struct vcpu *v) { - unsigned long intercepts, mask; + unsigned long mask; ASSERT(v == current); @@ -1057,12 +1064,11 @@ void vmx_update_debug_state(struct vcpu *v) if ( !cpu_has_monitor_trap_flag ) mask |= 1u << TRAP_debug; - intercepts = __vmread(EXCEPTION_BITMAP); if ( v->arch.hvm_vcpu.debug_state_latch ) - intercepts |= mask; + v->arch.hvm_vmx.exception_bitmap |= mask; else - intercepts &= ~mask; - __vmwrite(EXCEPTION_BITMAP, intercepts); + v->arch.hvm_vmx.exception_bitmap &= ~mask; + vmx_update_exception_bitmap(v); } static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) @@ -1124,7 +1130,8 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) vmx_set_segment_register(v, s, ®[s]); v->arch.hvm_vcpu.hw_cr[4] |= X86_CR4_VME; __vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]); - __vmwrite(EXCEPTION_BITMAP, 0xffffffff); + v->arch.hvm_vmx.exception_bitmap = 0xffffffff; + vmx_update_exception_bitmap(v); } else { @@ -1136,11 +1143,11 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) ((v->arch.hvm_vcpu.hw_cr[4] & ~X86_CR4_VME) |(v->arch.hvm_vcpu.guest_cr[4] & X86_CR4_VME)); __vmwrite(GUEST_CR4, v->arch.hvm_vcpu.hw_cr[4]); - __vmwrite(EXCEPTION_BITMAP, - HVM_TRAP_MASK + v->arch.hvm_vmx.exception_bitmap = HVM_TRAP_MASK | (paging_mode_hap(v->domain) ? 0 : (1U << TRAP_page_fault)) - | (1U << TRAP_no_device)); + | (1U << TRAP_no_device); + vmx_update_exception_bitmap(v); vmx_update_debug_state(v); } } diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h index 42a216028b..eb9ab7a676 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -97,6 +97,7 @@ struct arch_vmx_struct { /* Cache of cpu execution control. */ u32 exec_control; u32 secondary_exec_control; + u32 exception_bitmap; #ifdef __x86_64__ struct vmx_msr_state msr_state; diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vmx/vmx.h index 471138e62f..7a490a7d01 100644 --- a/xen/include/asm-x86/hvm/vmx/vmx.h +++ b/xen/include/asm-x86/hvm/vmx/vmx.h @@ -60,6 +60,8 @@ void vmx_do_resume(struct vcpu *); void vmx_vlapic_msr_changed(struct vcpu *v); void vmx_realmode(struct cpu_user_regs *regs); void vmx_update_debug_state(struct vcpu *v); +void vmx_update_exception_bitmap(struct vcpu *v); + /* * Exit Reasons @@ -292,16 +294,6 @@ static inline unsigned long __vmread_safe(unsigned long field, int *error) return ecx; } -static inline void __vm_set_bit(unsigned long field, unsigned int bit) -{ - __vmwrite(field, __vmread(field) | (1UL << bit)); -} - -static inline void __vm_clear_bit(unsigned long field, unsigned int bit) -{ - __vmwrite(field, __vmread(field) & ~(1UL << bit)); -} - static inline void __invept(int type, u64 eptp, u64 gpa) { struct { -- 2.30.2